class Pen {
    constructor() {
        document.onmousedown = this.down.bind(this);
    }
    down() {
        document.onmousemove = this.move.bind(this);
        document.onmouseup = this.up.bind(this);
    }
    move(e) {
        var e = e || event;
        var div = document.getElementById("box");
        div.style.cssText = "left:" + e.clientX + "px; top:" + e.clientY + "px;";
        div.style.background = "blue";
    }
    up() {
        document.onmousemove = null;
        document.onmouseup = null;
    }
}

new Pen();